"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var login_service_1 = require("app/lib/service/login.service");
var local_storage_service_1 = require("../../lib/service/local-storage.service");
var api_1 = require("../../../config/api");
var http_service_1 = require("../../lib/service/http.service");
var LoginData = /** @class */ (function () {
    function LoginData() {
    }
    return LoginData;
}());
exports.LoginData = LoginData;
var LoginComponent = /** @class */ (function () {
    function LoginComponent(loginService, route, localStorageService, httpService) {
        this.loginService = loginService;
        this.route = route;
        this.localStorageService = localStorageService;
        this.httpService = httpService;
        this.loginData = new LoginData();
        this.aliyunOssOutputUrl = api_1.AliyunOssOutputUrl;
    }
    LoginComponent.prototype.ngOnInit = function () {
        // this.localStorageService.clearNowAppleto();
        // this.localStorageService.clearAppletToken();
        // localStorage.removeItem('baseInfo');
    };
    LoginComponent.prototype.login = function () {
        var _this = this;
        this.isLoading = true;
        this.loginService.doLogin(this.username, this.password).subscribe(function (rs) {
            if (rs.code === 2000) {
                _this.loginData = rs;
                var time = new Date(rs.time);
                var now_time = time.getTime() / 1000;
                _this.loginData.data.user.time = now_time + '';
                // 清理之前登录的信息
                _this.localStorageService.clearAll();
                // 保存当前的信息
                _this.localStorageService.setNowApplet(rs.data.nowApplet);
                _this.localStorageService.setUserInfo(_this.loginData.data.user);
                _this.localStorageService.setToken(_this.loginData.data.token);
                return _this.redirectToDefaultApp(_this.loginData.data['nowApplet']);
            }
            else {
                _this.isLoading = false;
                return _this.alerts = [{
                        type: 'danger',
                        msg: rs.message,
                    }];
            }
        }, function (err) { return console.log(err); });
    };
    LoginComponent.prototype.getAppletList = function () {
        var _this = this;
        var id = this.localStorageService.getUserInfo().id;
        var url = api_1.adSystemApiUrl + "/v1/member/applets/list?userID=" + id;
        return this.httpService.httpGetAuth(url).subscribe(function (res) {
            _this.myAppletList = res.data.data;
        });
    };
    LoginComponent.prototype.redirectToDefaultApp = function (applet) {
        this.localStorageService.setNowApplet(applet);
        this.route.navigate(['/member/product/list/all']);
        if (this.route.url != '/home/login') {
            this.isLoading = false;
        }
    };
    LoginComponent = __decorate([
        core_1.Component({
            selector: 'app-login',
            templateUrl: 'login.component.html',
            styleUrls: ['login.component.scss'],
            providers: [login_service_1.LoginService, local_storage_service_1.LocalStorageService, http_service_1.HttpService],
        })
    ], LoginComponent);
    return LoginComponent;
}());
exports.LoginComponent = LoginComponent;
